//
//  ZRImageBrower.m
//  Hand shadow
//
//  Created by A-01 on 2020/7/21.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "ZRImageBrower.h"

@interface ZRImageBrower ()

@property (nonatomic, weak)UIImageView *imageView;

@end

@implementation ZRImageBrower


+ (void)showImage:(UIImageView *)avatarImageView{
    
    UIImage *image = avatarImageView.image;
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    backgroundView.backgroundColor = [UIColor blackColor];
    backgroundView.alpha = 0;
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = image;
    imageView.tag = 99;
    imageView.backgroundColor = ZRWhiteColor;
    

    [window addSubview:backgroundView];
    [window addSubview:imageView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
    [backgroundView addGestureRecognizer:tap];
    
    [UIView animateWithDuration:0.2 animations:^{
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.centerX.mas_equalTo(backgroundView);
            make.width.height.mas_equalTo(135 * 2);
        }];
        backgroundView.alpha = 0.7;
    } completion:^(BOOL finished) {
        
    }];
}
 
+ (void)hideImage:(UITapGestureRecognizer *)tap{
    UIView *backgroundView = tap.view;
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    for (UIImageView *imageView in window.subviews) {
        
        if (imageView.tag == 99) {
            
            [imageView removeFromSuperview];
        }
    }
    
    [backgroundView removeFromSuperview];
    
}


@end
